package br.ufpe.cin.mac.util;


import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

public class ConnectionPackage {

	Socket socket;
	ObjectOutputStream out;
	ObjectInputStream in;
	
	public ConnectionPackage(Socket socket) {
		try {
			this.socket = socket;
		//	this.out = new ObjectOutputStream(this.socket.getOutputStream());
//			this.in =  new ObjectInputStream(this.socket.getInputStream());		
		}
		catch(Exception e) {
			e.printStackTrace();
		}
	}
	
	public ObjectInputStream getIn() {
		if(this.in == null) {
			try {
				this.setIn(new ObjectInputStream(socket.getInputStream()));
				//System.err.println("**************************");
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return in;
	}
	public ObjectOutputStream getOut() {
		if(this.out == null) {
			try {
				this.setOut(new ObjectOutputStream(socket.getOutputStream()));
			} 
			catch (IOException e) {
				e.printStackTrace();
			}
		}
		return out;
	}
	public Socket getSocket() {
		return socket;
	}

	public void setIn(ObjectInputStream in) {
		this.in = in;
	}

	public void setOut(ObjectOutputStream out) {
		this.out = out;
	}
	
}
